package com.net.framework.help.share;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;

import com.net.framework.help.utils.AppAvailableListener;
import com.net.framework.help.utils.StringUtil;
import com.net.framework.help.utils.UIUtils;

/**
 * Author：xiaobin.zhang
 * Email：154722566@qq.com
 * Date：2017-12-13 11:09
 * Desc：<--功能描述-->
 */
public class LocalShareUtile {
    private Activity activity;

    public LocalShareUtile(Activity activity) {
        this.activity = activity;
    }

    /**
     * 图片、文字一起分享到微信朋友圈（调用系统功能）
     */
    public void shareWeixinTimeLine(String desc, Uri uris) {
        if (!AppAvailableListener.isWeixinAvilible(activity)) {
            UIUtils.shortToast("您的手机上未安装微信~");
            return;
        }
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI"));
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_STREAM, uris);
        if (!StringUtil.isBlank(desc)) {
            intent.putExtra("Kdescription", desc);
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(intent);
    }

    /**
     * 图片发送给微信朋友
     */
    public void shareWeixinFriend(Uri uris) {
        if (!AppAvailableListener.isWeixinAvilible(activity)) {
            UIUtils.shortToast("您的手机上未安装微信~");
            return;
        }
        Intent localIntent = new Intent();
        localIntent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI"));
        localIntent.setType("image/*");
        localIntent.setAction(Intent.ACTION_SEND);
        localIntent.putExtra(Intent.EXTRA_STREAM, uris);
        localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(localIntent);
    }

    /**
     * 图片分享到微博
     *
     * @param desc
     * @param uris
     */
    public void shareWeibo(String desc, Uri uris) {
        if (!AppAvailableListener.isWeiboClientAvailable(activity)) {
            UIUtils.shortToast("您的手机上未安装微博~");
            return;
        }
        Intent localIntent = new Intent();
        localIntent.setType("image/*");
        localIntent.setAction(Intent.ACTION_SEND);
        if (!StringUtil.isBlank(desc)) {
            localIntent.putExtra(Intent.EXTRA_TEXT, desc);
        }
        localIntent.putExtra(Intent.EXTRA_STREAM, uris);
        localIntent.setComponent(new ComponentName("com.sina.weibo", "com.sina.weibo.composerinde.ComposerDispatchActivity"));
        localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(localIntent);
    }

    /**
     * 图片发送给QQ好友
     *
     * @param uris
     */
    public void shareQQFriend(Uri uris) {
        if (!AppAvailableListener.isQQClientAvailable(activity)) {
            UIUtils.shortToast("您的手机上未安装QQ~");
            return;
        }
        Intent localIntent = new Intent();
        localIntent.setType("image/*");
        localIntent.setAction(Intent.ACTION_SEND);
        localIntent.putExtra(Intent.EXTRA_STREAM, uris);
        localIntent.setComponent(new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity"));
        localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(localIntent);
    }

    /**
     * 图片分享到QQ空间
     *
     * @param desc
     * @param uris
     */
    public void shareQQZone(String desc, Uri uris) {
        if (!AppAvailableListener.isQZoneClientAvailable(activity)) {
            UIUtils.shortToast("您的手机上未安装QQ空间~");
            return;
        }
        Intent localIntent = new Intent();
        localIntent.setAction(Intent.ACTION_SEND);
        localIntent.setType("image/*");
        if (!StringUtil.isBlank(desc)) {
            localIntent.putExtra(Intent.EXTRA_TEXT, desc);
        }
        localIntent.putExtra(Intent.EXTRA_STREAM, uris);
        localIntent.setComponent(new ComponentName("com.qzone", "com.qzonex.module.operation.ui.QZonePublishMoodActivity"));
        localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(localIntent);
    }
}
